package terra.network.packet.client;

import org.jboss.netty.buffer.ChannelBuffer;

import terra.network.packet.Packet;

public class PlayerControl extends Packet {

	public boolean UP = false;
	public boolean DOWN = false;
	public boolean LEFT = false;
	public boolean RIGHT = false;
	public boolean CTRL = false;
	public boolean ALT = false;
	public boolean JUMP = false;
	public boolean LMB = false;
	public boolean RMB = false;	
	public int mouseX = -1,mouseY = -1;
	
	public PlayerControl() {
	}

	@Override
	public ChannelBuffer toBuffer() {
		ChannelBuffer buf = getNewBuffer();
		buf.writeByte(getId());
		buf.writeByte(UP ? 1 : 0);
		buf.writeByte(DOWN ? 1 : 0);
		buf.writeByte(LEFT ? 1 : 0);
		buf.writeByte(RIGHT ? 1 : 0);
		buf.writeByte(CTRL ? 1 : 0);
		buf.writeByte(ALT ? 1 : 0);
		buf.writeByte(JUMP ? 1 : 0);
		buf.writeByte(LMB ? 1 : 0);
		buf.writeByte(RMB ? 1 : 0);
		buf.writeInt(mouseX);
		buf.writeInt(mouseY);		
		return buf;
	}

	@Override
	public Packet fromBuffer(ChannelBuffer buf) {
		UP = buf.readByte() == 1 ? true : false;
		DOWN = buf.readByte() == 1 ? true : false;
		LEFT = buf.readByte() == 1 ? true : false;
		RIGHT = buf.readByte() == 1 ? true : false;
		CTRL = buf.readByte() == 1 ? true : false;
		ALT = buf.readByte() == 1 ? true : false;
		JUMP = buf.readByte() == 1 ? true : false;
		LMB = buf.readByte() == 1 ? true : false;
		RMB = buf.readByte() == 1 ? true : false;
		mouseX = buf.readInt();
		mouseY = buf.readInt();		
		return this;
	}

	@Override
	public int getLength() {
		return 18;
	}

	@Override
	public boolean isDynamicLength() {
		return false;
	}

	@Override
	public byte getId() {
		return 3;
	}

	@Override
	public byte getPriority() {
		return PRIOR_HIGH;
	}

}
